﻿using System.Linq;

namespace 字节数据转换
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //int i就是int的instance
            int i = BitConverter.ToInt32(new byte[] { 0xff, 0x10, 0x03, 0x10 });
            Console.WriteLine($"字节转int：{i}");

            byte[] bytes = BitConverter.GetBytes(i);
            Console.WriteLine($"int转字节数组");

            //var byteObj = bytes.Where(m => m == 0x10);

            // 将数组元素以"，"逗号连接成字符串
            var byteStr = string.Join("-----", bytes);
            var byteStr2 = Join("-----", bytes);
            Console.WriteLine($"int转字节数组{byteStr}");

            string stri = i.ToString();
            Console.WriteLine($"int转string:{stri}");
        }

        /// <summary>
        /// 自动思考实现这个功能
        /// </summary>
        /// <param name="seqerator"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        static string Join(string seqerator, byte[] values)
        {
            var len = values.Length;
            string output = string.Empty;
            for (int i = 0; i < len; i++)
            {
                output = output + values[i] + seqerator;
            }
            return output;
        }
    }
}
